Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel multi registries #8955

Merged

Conversation

oheger-bosch
Copy link
Member

This PR adds support for multiple registry services defined in the .bazelrc file.

Taking over from @nnobelis during his vacation.

@oheger-bosch oheger-bosch requested a review from a team as a code owner August 5, 2024 07:58
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.64%. Comparing base (b694901) to head (e25b787).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8955   +/-   ##
=========================================
  Coverage     67.64%   67.64%           
  Complexity     1168     1168           
=========================================
  Files           244      244           
  Lines          7783     7783           
  Branches        867      867           
=========================================
  Hits           5265     5265           
  Misses         2161     2161           
  Partials        357      357           
Flag Coverage Δ
funTest-docker 67.39% <ø> (ø)
funTest-non-docker 33.92% <ø> (ø)
test 37.90% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@MarcelBochtler MarcelBochtler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the minor nit the changes look good.

There were multiple places that checked and transformed URLs to create
either local or remote Bazel module registry service instances.
Centralize this logic, so that redundancy can be reduced.

Signed-off-by: Oliver Heger <[email protected]>
This is a special `BazelModuleRegistryService` implementation that
wraps an arbitrary number of other registry services. On receiving a
request, it delegates to the other registries and returns the first
successful result.

This implementation is going to be used to support multiple registries
declared in a `.bazelrc` file.

Signed-off-by: Oliver Heger <[email protected]>
For Bazel < 7.2.0, if the `.bazelrc` file lists multiple registries,
use all of them to query package metadata.

Fixes oss-review-toolkit#8801.

Signed-off-by: Oliver Heger <[email protected]>
@haikoschol
Copy link
Contributor

I don't understand all of the code but wonder why we need both the CompositeBazelModuleRegistryService and the MultiBazelModuleRegistryService.

Is this due to the differences between Bazel <7.2 and >=7.2 lock files? Would it be possible to have those differences dealt with before MultiBazelModuleRegistryService is instantiated and thus have it cover both cases? Or am I completely misunderstanding the point?

@oheger-bosch
Copy link
Member Author

I don't understand all of the code but wonder why we need both the CompositeBazelModuleRegistryService and the MultiBazelModuleRegistryService.

Is this due to the differences between Bazel <7.2 and >=7.2 lock files? Would it be possible to have those differences dealt with before MultiBazelModuleRegistryService is instantiated and thus have it cover both cases? Or am I completely misunderstanding the point?

You are mostly right; the different implementations deal with differences in the lock file formats. However, they apply different logic; therefore, I think they cannot be merged that easily:

  • MultiBazelModuleRegistryService is used to handle multiple registries defined in a Bazel < 7.2 lock file. It is rather dump and simply tries the registries one after another until it gets a success result.
  • CompositeBazelModuleRegistryService has more information available from a Bazel >= 7.2 lock file which lists the packages together with the URLs of registries from where they have been downloaded. Thus it can determine the registry to delegate to and does not have to use a trial-and-error approach.

There is a TODO comment in CompositeBazelModuleRegistryService to check for a package in other registries as well if it cannot be found in the one from which it was retrieved originally. This could maybe be implemented using a combination of the approaches that are currently there. But I would rather address this in a later refactoring step.

I have to admit that the names of the registry service implementations are probably not ideal. So, proposals for better names would be welcome.

@haikoschol
Copy link
Contributor

* `CompositeBazelModuleRegistryService` has more information available from a Bazel >= 7.2 lock file which lists the packages together with the URLs of registries from where they have been downloaded. Thus it can determine the registry to delegate to and does not have to use a trial-and-error approach.

Thanks for the explanation! That makes sense.

I have to admit that the names of the registry service implementations are probably not ideal. So, proposals for better names would be welcome.

Yeah, I also thought the names are confusingly generic and similar, but putting the Bazel version number in them seems worse and I couldn't come up with anything else either.

@oheger-bosch oheger-bosch merged commit 378f6e2 into oss-review-toolkit:main Aug 6, 2024
22 checks passed
@oheger-bosch oheger-bosch deleted the bazel_multi_registries branch August 6, 2024 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants